﻿function checkemail(str)
{
    var ename = str.split('@').shift(),
		fisrtCharPattern = lastCharPattern = /[a-zA-Z0-9]/,
		pattern = /^([a-zA-Z0-9-_.]){2,64}@([a-zA-Z0-9.]){2,}(\.(com|cn|net|org|info|edu|mil|gov|biz|us|tv|cc)){1}$/i;
    return (str.length <= 50 && pattern.test(str) && fisrtCharPattern.test(ename.substr(0, 1)) && lastCharPattern.test(ename.substr(ename.length - 1, 1))) ? true : false;
}

function FindPassword()
{
    var email = $('#email').val();
    var captcode = $('#captcode').val();

    if ($.trim(email) == '')
    {
        alert('请输入邮箱');
        return false;
    }
    if (!checkemail(email))
    {
        alert('邮箱格式错误');
        return false;
    }
    if ($.trim(captcode) == '')
    {
        alert('请输入验证码');
        return false;
    }
    $.ajax({
        type: "GET",
        cache: false,
        url: 'ajax/FindPassword.aspx',
        data: ({ email: email, captcode: captcode }),
        dataType: 'html',
        success: function (obj)
        {
            if (obj == '1')//成功
            {
                alert('系统已经将密码发送到邮箱中，请查收');
                window.location = 'Index.aspx';
                return true;
            }
            else if (obj == '2')
            {
                alert('验证码错误');
                chgCap();
                return;
            }
            else if (obj == '3')
            {
                alert('邮箱在系统中不存在');
                chgCap();
                return;
            }
            else if (obj == '-1')
            {
                alert('发送邮件失败，请稍后在试或点击下方意见反馈');
                window.location = 'Index.aspx';
                return true;
            }
            chgCap();
            alert('找回密码失败');
            return;

        }
    });
}

$(document).ready(
	function ()
	{
	    $('#subbutton').click(function () { FindPassword(); return false; });
	}
)